
package world0.items;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Polygon;
import org.newdawn.slick.geom.Shape;

public abstract class Item {

	protected String name;
	protected Image image;
	
	protected int itemSlotIndex;
	private int x = 0;
	private int y = 0;
	private int width = 0;
	private int height = 0;
	
	private int resetX = 0;
	private int resetY = 0;
	private int resetWidth = 0;
	private int resetHeight = 0;
	
	private Polygon area;
	
	protected Item(String name, Image image) {
		this.name = name;
		this.image = image;
		
		createField();
	}
	
	public void draw(Graphics g) {
		/* Debug.draw 
		g.setColor(Color.red);
		g.fill(area);
		
		image.draw(x, y);
		*/
		g.setColor(Color.white);
		g.texture(area, image, true);
	}
	
	private void refresh() {
		area = null;
		createField();
	}
	
	private void createField() {
		area = new Polygon();
		area.addPoint(0, 0);
		area.addPoint(width, 0);
		area.addPoint(width, height);
		area.addPoint(0, height);
		area.setLocation(x, y);
	}
	
	public void toOldPosition() {
		x = resetX;
		y = resetY;
		width = resetWidth;
		height = resetHeight;
		refresh();
	}
	
	public boolean isHit(int mouseX, int mouseY) {
		boolean isHit = false;
		if(area.contains(mouseX, mouseY)) {
			isHit = true;
		}
		return isHit;
	}
	
	public void setPosition(int x, int y) {
		this.x = x;
		this.y = y;
		refresh();
	}
	
	public int getResetX() {
		return resetX;
	}

	public void setResetX(int resetX) {
		this.resetX = resetX;
	}

	public int getResetY() {
		return resetY;
	}

	public void setResetY(int resetY) {
		this.resetY = resetY;
	}

	public void setPositionResetX(int x, int width) {
		this.resetX = x;
		this.resetWidth = width;
	}
	
	public void setPositionResetY(int y, int height) {
		this.resetY = y;
		this.resetHeight = height;
	}
	
	public Shape getShape() {
		return area;
	}
	
	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public void setWidth(int width) {
		this.width = width;
		refresh();
	}
	
	public void setHeight(int height) {
		this.height = height;
		refresh();
	}
	
	public void setSize(int height, int width) {
		this.width = width;
		this.height = height;
		refresh();
	}
	
	public String getName() {
		return name;
	}
}
